<?php
	class MemberResume extends AppModel{
		var $name="MemberResume";
		var $useTable="member_resume_info";
		var $primaryKey = 'id';
		//@author wang.wei add 2012/3/15 start
		var $encrypt_col = array();
		//@author wang.wei add 2012/3/15 end
		
		var $hasOne = array('MemberEducation' =>
				array('className'     => 'MemberEducation',
						'conditions'    => '"MemberEducation".deleted is null',
						'order'         => '',
						'limit'         => '',
						'foreignKey'    => 'member_id'
				)
		);
		
		var $htmlValid = array();
		/*
		 * @author wang.wei add
		* 2012/02/14
		* */
		function RegValid($Valid,$data)
		{
		
			$message='';
			$validdata=array();

			$message.= $this->MemberEducationValid($Valid,$data,'edu_school');
			//$message.= $this->MemberEducationValid($Valid,$data,'edu_dep');
			//$message.= $this->MemberEducationValid($Valid,$data,'edu_degree');
			//$message.= $this->MemberEducationValid($Valid,$data,'edu_start');
			//$message.= $this->MemberEducationValid($Valid,$data,'edu_end');
			
			$message.= $this->MemberWorkValid($Valid,$data,'exp_work_locaiton');
			$message.= $this->MemberWorkContentValid($Valid,$data);
			
			//$message.= $this->MemberWorkValid($Valid,$data,'exp_work_public_flg');
			//$message.= $this->MemberWorkValid($Valid,$data,'exp_work_start_year');
			//$message.= $this->MemberWorkValid($Valid,$data,'exp_work_start_month');
			//$message.= $this->MemberWorkValid($Valid,$data,'exp_work_end_year');
			//$message.= $this->MemberWorkValid($Valid,$data,'exp_work_end_month');
			//$message.= $this->MemberWorkValid($Valid,$data,'exp_work_flg');
			//$message.= $this->MemberWorkValid($Valid,$data,'exp_work_position');
			//$message.= $this->MemberWorkValid($Valid,$data,'exp_work_emp_type');
			
			//print_r($data['MemberExpWorktype']);
			$message.= $this->MemberExpWorktype($Valid,$data,'exp_category');
			$message.= $this->MemberExpWorktype($Valid,$data,'exp_worktype_big');
			$message.= $this->MemberExpWorktype($Valid,$data,'exp_worktype_small');
			$message.= $this->MemberExpWorktype($Valid,$data,'exp_year');
			
			$messageTag=$Valid->ErrorMsg($data,'MemberResume/now_income','number');
			if(!empty($messageTag)){
				$this->htmlValid[]='MemberResumenowIncome';
				$message.=$messageTag;
				$messageTag='';
			}
			$messageTag=$Valid->ErrorMsg($data,'MemberResume/now_income','maxlength','9');
			if(!empty($messageTag)){
				$this->htmlValid[]='MemberResumenowIncome';
				$message.=$messageTag;
				$messageTag='';
			}
			if($data['MemberResume']['now_income']){
				$message .= $Valid->ErrorMsg($data, 'MemberResume/now_income_cur', 'required');
			}			
		
			return $message;
		}
		/*
		 * @author wang.wei add
		* 2012/02/14
		* */
		function MemberEducationValid($Valid,$data,$field){
			$message='';
			for($i=0; $i<count($data['MemberEducation'][$field]); $i++){
				if(!empty($data['MemberEducation'][$field][$i])){
					$validdata['MemberEducation']['edu_school'] = $data['MemberEducation']['edu_school'][$i];
					$validdata['MemberEducation']['edu_dep'] = $data['MemberEducation']['edu_dep'][$i];
					$validdata['MemberEducation']['edu_degree'] = $data['MemberEducation']['edu_degree'][$i];
					$validdata['MemberEducation']['edu_start'] = $data['MemberEducation']['edu_start'][$i];
					$validdata['MemberEducation']['edu_end'] = $data['MemberEducation']['edu_end'][$i];
					$validdata['MemberEducation']['edu_start_month'] = $data['MemberEducation']['edu_start_month'][$i];
					$validdata['MemberEducation']['edu_end_month'] = $data['MemberEducation']['edu_end_month'][$i];
					$validdata['MemberEducation']['edu_status'] = $data['MemberEducation']['edu_status'][$i];
					
					$message.=$Valid->ErrorMsg($validdata,'MemberEducation/edu_school','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberEducation/edu_dep','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberEducation/edu_degree','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberEducation/edu_start','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberEducation/edu_end','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberEducation/edu_start_month','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberEducation/edu_end_month','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberEducation/edu_status','required');
					
					$validdata['MemberEducation']['edu_start_check'] = $validdata['MemberEducation']['edu_start'].'-'.$validdata['MemberEducation']['edu_start_month'];
					$validdata['MemberEducation']['edu_end_check'] = $validdata['MemberEducation']['edu_end'].'-'.$validdata['MemberEducation']['edu_end_month'];
					$message.= $Valid->ErrorMsg($validdata,'MemberEducation/edu_start_check','checkdatesize','MemberEducation/edu_end_check');

					if(!$Valid->required($validdata['MemberEducation']['edu_school'])){
						$this->htmlValid[]='MemberEducationEduSchool'.$i;
					}
					if(!$Valid->required($validdata['MemberEducation']['edu_dep'])){
						$this->htmlValid[]='MemberEducationEduDep'.$i;
					}
				}
			}

			return $message;
		}
		/*
		 * @author wang.wei add
		* 2012/02/14
		* */
		function MemberWorkValid($Valid,$data,$field){
			$message='';
			for($i=0; $i<count($data['MemberWork'][$field]); $i++){
				if(!empty($data['MemberWork'][$field][$i])){
					$validdata['MemberWork']['exp_work_locaiton'] = $data['MemberWork']['exp_work_locaiton'][$i];
					//$validdata['MemberWork']['exp_work_public_flg'] = $data['MemberWork']['exp_work_public_flg'][$i];
					$validdata['MemberWork']['exp_work_start_year'] = $data['MemberWork']['exp_work_start_year'][$i];
					$validdata['MemberWork']['exp_work_start_month'] = $data['MemberWork']['exp_work_start_month'][$i];
					$validdata['MemberWork']['exp_work_end_year'] = $data['MemberWork']['exp_work_end_year'][$i];
					$validdata['MemberWork']['exp_work_end_month'] = $data['MemberWork']['exp_work_end_month'][$i];
					//$validdata['MemberWork']['exp_work_flg'] = $data['MemberWork']['exp_work_flg'][$i];
					$validdata['MemberWork']['exp_work_position'] = $data['MemberWork']['exp_work_position'][$i];
					$validdata['MemberWork']['exp_work_emp_type'] = $data['MemberWork']['exp_work_emp_type'][$i];
					$message.=$Valid->ErrorMsg($validdata,'MemberWork/exp_work_locaiton','required');
					//$message.=$Valid->ErrorMsg($validdata,'MemberWork/exp_work_public_flg','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberWork/exp_work_start_year','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberWork/exp_work_start_month','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberWork/exp_work_end_year','required');
					if($validdata['MemberWork']['exp_work_end_year'] != 'work_flg'){
						$message.=$Valid->ErrorMsg($validdata,'MemberWork/exp_work_end_month','required');
						if($i>0){
							$validdata['MemberWork']['exp_start_check'] = $validdata['MemberWork']['exp_work_start_year'].'-'.$validdata['MemberWork']['exp_work_start_month'];
							$validdata['MemberWork']['exp_end_check'] = $validdata['MemberWork']['exp_work_end_year'].'-'.$validdata['MemberWork']['exp_work_end_month'];
							$message.= $Valid->ErrorMsg($validdata,'MemberWork/exp_start_check','checkdatesize','MemberWork/exp_end_check');
						}else{
							$validdata['MemberWork']['exp_start_check1'] = $validdata['MemberWork']['exp_work_start_year'].'-'.$validdata['MemberWork']['exp_work_start_month'];
							$validdata['MemberWork']['exp_end_check1'] = $validdata['MemberWork']['exp_work_end_year'].'-'.$validdata['MemberWork']['exp_work_end_month'];
							$message.= $Valid->ErrorMsg($validdata,'MemberWork/exp_start_check1','checkdatesize','MemberWork/exp_end_check1');
						}

					}
					//$message.=$Valid->ErrorMsg($validdata,'MemberWork/exp_work_flg','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberWork/exp_work_position','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberWork/exp_work_emp_type','required');

					if(!$Valid->required($validdata['MemberWork']['exp_work_locaiton'])){
						$this->htmlValid[]='MemberWorkExpWorkLocaiton'.$i;
					}
				}
			}
			return $message;
		}
		/*
		 * @author wang.wei add
		* 2012/12/07
		* */
		function MemberWorkContentValid($Valid,$data){
			$message='';
			for($i=0; $i<count($data['MemberWork']['exp_work_content']); $i++){
				if(!empty($data['MemberWork']['exp_work_content'][$i])){
					$validdata['MemberWork']['exp_work_content'] = $data['MemberWork']['exp_work_content'][$i];
					$message.=$Valid->ErrorMsg($validdata,'MemberWork/exp_work_content','mbmaxlength','1000');
		
					if(!$Valid->mbmaxlength($validdata['MemberWork']['exp_work_content'],'1000')){
						$this->htmlValid[]='MemberWorkExpWorkContent'.$i;
					}
				}
			}
			return $message;
		}
		/*
		 * @author wang.wei add
		* 2012/02/14
		* */
		function MemberExpWorktype($Valid,$data,$field){
			$message='';
			for($i=0; $i<count($data['MemberExpWorktype'][$field]); $i++){
				if(!empty($data['MemberExpWorktype'][$field][$i])){
					$validdata['MemberExpWorktype']['exp_category'] = $data['MemberExpWorktype']['exp_category'][$i];
					$validdata['MemberExpWorktype']['exp_worktype_big'] = $data['MemberExpWorktype']['exp_worktype_big'][$i];
					$validdata['MemberExpWorktype']['exp_worktype_small'] = $data['MemberExpWorktype']['exp_worktype_small'][$i];
					$validdata['MemberExpWorktype']['exp_year'] = $data['MemberExpWorktype']['exp_year'][$i];
					$message.=$Valid->ErrorMsg($validdata,'MemberExpWorktype/exp_category','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberExpWorktype/exp_category','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberExpWorktype/exp_worktype_big','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberExpWorktype/exp_worktype_small','required');
					$message.=$Valid->ErrorMsg($validdata,'MemberExpWorktype/exp_year','required');
				}
			}
			return $message;
		}
		
		/*
		 * @author wang.wei add
		* 2012/02/20
		* */
		function getMemberResumeAndEducationAndWorkAndworktype($member_id){
			$sql = "select
					a.id,										
					a.member_id,										
					b.edu_school,											
					b.edu_dep,											
					b.edu_degree,											
					b.edu_start,											
					b.edu_end,											
					c.exp_work_locaiton,											
					c.exp_work_start_year,											
					c.exp_work_start_month,											
					c.exp_work_end_year,											
					c.exp_work_end_month,											
					c.exp_work_flg,											
					c.exp_work_position,											
					c.exp_work_emp_type,											
					d.exp_category,											
					d.exp_worktype_big,											
					d.exp_worktype_small,											
					d.exp_year,											
					a.now_income_cur,											
					a.now_income,											
					a.exp_company,											
					a.note											
					from											
					member_resume_info a											
					left join member_education_info b on a.member_id=b.member_id and b.deleted is null											
					left join member_work_info c on a.member_id=c.member_id	and c.deleted is null										
					left join member_exp_worktype_info d on a.member_id=d.member_id	and d.deleted is null										
					where a.member_id='$member_id' and a.deleted is null ";
			$data = $this->query($sql);
			return $data;
		}
		
		/*
		 * @author wang.wei add
		* 2012/02/21
		* */
		function doDelete($id)
		{
		
			$sql="update member_resume_info MemberResume set deleted=now() ".
					" where MemberResume.id in ($id)";
			$this->query($sql);
		}
		
		/*
		 * @author wang.wei add
		* 2012/03/14
		* */
		function doDeleteFormMemberId($member_id) {
		
			$sql = "update member_resume_info MemberResume set deleted=now() " . " where MemberResume.member_id = '$member_id' and deleted is null";
			$this->query($sql);
		}
		
		/*
		 * @author wang.wei add
		* 2012/02/29
		* */
		function updateMemberResumePoint($id,$completion_point)
		{
		    if(empty($id)) {
		    	return;
		    }
			$sql="update member_resume_info MemberResume set completion_point=$completion_point ".
					" where MemberResume.id in ($id)";
			$this->query($sql);
		}
		
	}
?>